var qiniu = require("qiniu");
//需要填写你的 Access Key 和 Secret Key
qiniu.conf.ACCESS_KEY = 'rfceGlTpSFMah2Y8xwUA5JWSKQllZA73wVxTmu-F';
qiniu.conf.SECRET_KEY = '6V1D0OF_vUnnnmmrI7aotnUk42-I60EiBGo77fFh';
//要上传的空间
var bucket_name = 'hotchain';

function create_uptoken(bucket_name) {
    var putPolicy = new qiniu.rs.PutPolicy(bucket_name);
    return putPolicy.token();
}


/**
 * @api {post} /qiniu/getQiniuToken 获取七牛token
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName getQiniuToken
 * @apiGroup qiniu
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/qiniu/getQiniuToken'
 *
 * @apiSuccess {String}   token             七牛token
 * @apiSampleRequest http://copyright.hotchain.vip/api/qiniu/getQiniuToken
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function getQiniuToken(ctx) {
    ctx.body = { token: create_uptoken(bucket_name) }
}



/**
 * @apiDefine ERROR
 * @apiErrorExample {json} 错误返回:
 *     {
 *       "code": "错误码",
 *       "error": "错误描述",
 *       "msg":"错误信息"
 *     }
 */